﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using AxeFrog.Composition;

namespace AxeFrog
{
	[PartCreationPolicy(CreationPolicy.Shared)]
	public class Factory
	{
		private readonly ContainerManager _container;

		public Factory(ContainerManager container)
		{
			_container = container;
		}

		public T Create<T>()
		{
			return _container.Resolve<T>();
		}

		public T Create<T>(string contractName)
		{
			return _container.Resolve<T>(contractName);
		}

		public object Create(Type type)
		{
			return _container.Resolve(type);
		}

		public T TryCreate<T>()
		{
			return _container.TryResolve<T>();
		}

		public T TryCreate<T>(string contractName)
		{
			return _container.TryResolve<T>(contractName);
		}

		public object TryCreate(Type type)
		{
			return _container.TryResolve(type);
		}

		public IEnumerable<T> CreateAll<T>()
		{
			return _container.ResolveAll<T>();
		}

		public IEnumerable<T> CreateAll<T>(string contractName)
		{
			return _container.ResolveAll<T>(contractName);
		}

		public Lazy<T, TMetadata> Query<T, TMetadata>()
		{
			return _container.Query<T, TMetadata>();
		}

		public IEnumerable<Lazy<T, TMetadata>> QueryAll<T, TMetadata>()
		{
			return _container.QueryAll<T, TMetadata>();
		}
	}
}